package com.yunkeji.admin.controller.appuser;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.yunkeji.common.annotation.Log;
import com.yunkeji.common.annotation.RepeatSubmit;
import com.yunkeji.common.core.controller.BaseController;
import com.yunkeji.common.core.domain.PageQuery;
import com.yunkeji.common.core.domain.R;
import com.yunkeji.common.core.page.TableDataInfo;
import com.yunkeji.common.core.validate.AddGroup;
import com.yunkeji.common.core.validate.EditGroup;
import com.yunkeji.common.enums.BusinessType;
import com.yunkeji.common.utils.poi.ExcelUtil;
import com.yunkeji.dao.vo.AppUserWalletVo;
import com.yunkeji.system.domain.bo.AppUserWalletBo;
import com.yunkeji.system.service.IAppUserWalletService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Arrays;
import java.util.List;

/**
 * 用户钱包信息
 *
 * @author zhang
 * @date 2024-07-10
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/appUserWallet")
public class AppUserWalletController extends BaseController {

    private final IAppUserWalletService iAppUserWalletService;

    /** 查询用户钱包信息列表 */
    @SaCheckPermission("system:appUserWallet:list")
    @GetMapping("/list")
    public TableDataInfo<AppUserWalletVo> list(AppUserWalletBo bo, PageQuery pageQuery) {
        return iAppUserWalletService.queryPageList(bo, pageQuery);
    }

    /** 导出用户钱包信息列表 */
    @SaCheckPermission("system:appUserWallet:export")
    @Log(title = "用户钱包信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(AppUserWalletBo bo, HttpServletResponse response) {
        List<AppUserWalletVo> list = iAppUserWalletService.queryList(bo);
        ExcelUtil.exportExcel(list, "用户钱包信息", AppUserWalletVo.class, response);
    }

    /**
     * 获取用户钱包信息详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("system:appUserWallet:query")
    @GetMapping("/{id}")
    public R<AppUserWalletVo> getInfo(@NotNull(message = "主键不能为空") @PathVariable Long id) {
        return R.ok(iAppUserWalletService.queryById(id));
    }

    /** 新增用户钱包信息 */
    @SaCheckPermission("system:appUserWallet:add")
    @Log(title = "用户钱包信息", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody AppUserWalletBo bo) {
        return toAjax(iAppUserWalletService.insertByBo(bo));
    }

    /** 修改用户钱包信息 */
    @SaCheckPermission("system:appUserWallet:edit")
    @Log(title = "用户钱包信息", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody AppUserWalletBo bo) {
        return toAjax(iAppUserWalletService.updateByBo(bo));
    }

    /**
     * 删除用户钱包信息
     *
     * @param ids 主键串
     */
    @SaCheckPermission("system:appUserWallet:remove")
    @Log(title = "用户钱包信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空") @PathVariable Long[] ids) {
        return toAjax(iAppUserWalletService.deleteWithValidByIds(Arrays.asList(ids), true));
    }
}
